package com.sx.pipeline.ui.mine

import android.annotation.SuppressLint
import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.sx.pipeline.R
import com.sx.pipeline.repos.http.res.IdentityVO

/**
 * @Author: YY
 * @Date: 2022/6/27
 * @Desc: TODO
 */
class IdentityListAdapter(dataList: MutableList<IdentityVO>): BaseQuickAdapter<IdentityVO, BaseViewHolder>
    (R.layout.item_identity_list, dataList) {

    var clickId: Int = -1

    override fun convert(holder: BaseViewHolder, item: IdentityVO) {
        when(item.identity) {
            "0" -> {
                holder.setImageResource(R.id.image_icon, R.drawable.icon_identity_operate)
                holder.setText(R.id.tv_identity, "运营单位")
            }
            "1" -> {
                holder.setImageResource(R.id.image_icon, R.drawable.icon_identity_build)
                holder.setText(R.id.tv_identity, "施工单位")
            }
            "2" -> {
                holder.setImageResource(R.id.image_icon, R.drawable.icon_identity_supply)
                holder.setText(R.id.tv_identity, "供应商")
            }
        }

        if (item.isEnabled) {
            // 单选
            if (clickId == holder.layoutPosition) {
                holder.setImageResource(R.id.image_check, R.drawable.icon_radio_button_checked)
            } else {
                holder.setImageResource(R.id.image_check, R.drawable.icon_radio_button_dischecked)
            }
        } else {
            // 不可选择
            holder.setImageResource(R.id.image_check, R.drawable.icon_not_choice)
            holder.getView<ImageView>(R.id.image_check).isEnabled = false
        }

    }


    @SuppressLint("NotifyDataSetChanged")
    fun setSelectClickId(position: Int) {
        this.clickId = position
        notifyDataSetChanged()
    }
}